package cn.net.shuxing.yifu.common.back.controller;

import cn.net.shuxing.yifu.common.bean.User;
import cn.net.shuxing.yifu.common.bean.UserRole;
import cn.net.shuxing.yifu.common.constant.UserState;
import cn.net.shuxing.yifu.common.dto.BaseDto;
import cn.net.shuxing.yifu.common.service.UserCommonService;
import cn.net.shuxing.yifu.common.service.UserRoleService;
import cn.net.shuxing.yifu.common.service.UserService;
import cn.net.shuxing.yifu.common.service.UserWalletFrozeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserDeleteController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserCommonService userCommonService;

    @Autowired
    private UserRoleService userRoleService;

    /**
     * 销户
     * @param userId
     * @param userType
     * @return
     */
    @RequestMapping("/back/user/delete")
    public BaseDto deleteUser(Integer userId, Integer userType)
    {
        User user = userService.getByPrimaryKeyWithoutComplete(userId);
        if (user == null)
            return BaseDto.error("此用户不存在");
        if (!userService.hasRole(userId,userType))
            return BaseDto.error("用户无此身份");
        userCommonService.delete(userId,userType);
        return BaseDto.ok("销户完成");
    }

    /**
     * 获取应该被销户的用户id和身份(UserRole对象里有)
     * @return
     */
    @RequestMapping("/back/user/delete/list")
    public BaseDto getShouldDeleteUserRoleList()
    {
        List<UserRole> userRoles = userRoleService.searchByState(UserState.DELETE);
        return BaseDto.ok(userRoles);
    }
}
